package data_source

import (
	"gopkg.in/yaml.v3"
	"io/ioutil"
)

type MysqlConf struct {
	Host     string `json:"host"`
	Port     string `json:"port"`
	UserName string `json:"user_name"`
	Password string `json:"password"`
	DataBase string `json:"database"`
	LogoMode bool   `json:"logo_mode"`
}

// Config 定义了配置结构
type Config struct {
	Database struct {
		User     string `yaml:"user"`
		Password string `yaml:"password"`
		Host     string `yaml:"host"`
		Name     string `yaml:"name"`
		Port     string `yaml:"port"`
		LogoMode bool   `yaml:"logo_mode"`
	} `yaml:"database"`
}

var config *Config

func LoadMysqlConf() *MysqlConf {
	//config := tool.GetConfig().Oss
	mysql_conf := MysqlConf{}

	cfg, err := ioutil.ReadFile("./config/config.yaml")
	err = yaml.Unmarshal(cfg, &config)
	if err != nil {
		panic(err.Error())
	}
	mysql_conf.Host = config.Database.Host
	mysql_conf.Port = config.Database.Port
	mysql_conf.UserName = config.Database.User
	mysql_conf.Password = config.Database.Password
	mysql_conf.DataBase = config.Database.Name
	mysql_conf.LogoMode = config.Database.LogoMode

	return &mysql_conf

}
